/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Examples;

import homomorphism.set.SetHomomorphismInterface;
import org.apache.hadoop.io.Text;
import utility.dPair;

/**
 *
 * @author takeshi
 */
public class WordCount implements SetHomomorphismInterface< Text , dPair<Text,Integer> >{

    public dPair<Text, Integer> filter( Text  val) {
        return  new dPair<Text, Integer>(val, 1);
    }

    public dPair<Text, Integer> plus(dPair<Text, Integer> a, dPair<Text, Integer> b) {
       if(a.getKey().compareTo(b.getKey()) != 0 )
           throw new UnsupportedOperationException("Wrong! key shou be the same! ");
       else
           return new dPair(a.getKey(), a.getValue() + b.getValue());
    }

}
